package com.meihua.shellapp.utils;

import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

import com.meihua.shellapp.base.MyApplication;

/**
 * 作者：lc on 2017/10/9.
 * 邮箱：lc0607live@163.com
 */

public class ToastUtils {

    private Toast toast;

    private ToastUtils() {
    }

    private static ToastUtils utils;

    public static ToastUtils getInstance() {
        if (utils == null) {
            utils = new ToastUtils();
        }
        return utils;
    }

    /**
     * 提示
     *
     * @param message
     */
    public void showToast(Object message) {
        if (toast == null) {
            toast = Toast.makeText(MyApplication.getInstance().getApplicationContext(), message.toString(), Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.BOTTOM, 0, 200);
        } else {
            toast.setText(message.toString());
            toast.setGravity(Gravity.BOTTOM, 0, 200);
        }
        toast.show();
//        Toast.makeText(MyApplication.getInstance().getApplicationContext(), message.toString(), Toast.LENGTH_SHORT).show();
    }

    /**
     * 显示在中间的toast
     *
     * @param message
     */
    public void showToastCenter(Object message) {
        if (toast == null) {
            toast = Toast.makeText(MyApplication.getInstance().getApplicationContext(), message.toString(), Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
        } else {
            toast.setText(message.toString());
            toast.setGravity(Gravity.CENTER, 0, 0);
        }
        toast.show();
    }
}
